<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Advantage;
use App\Models\Service;
use Illuminate\Http\Request;


class ServiceController extends Controller
{
    public function index()
    {
        $services = Service::all();
        return $services->toArray();
    }

    public function show(Service $service)
    {
        return $service;
    }

    public function store(Request $request, Service $service)
    {
        $request->validate([
            'name' => ['required'],
            'introduce' => ['required']
        ]);
        $service->create($request->input());

        return $this->message('添加成功');
    }

    public function destroy(Request $request, Service $service)
    {
        $service->delete();
        return $this->message('删除成功');
    }

    public function update(Request $request, Service $service)
    {
        $request->validate([
            'name' => ['required'],
            'introduce' => ['required']
        ]);
        $service->update($request->input());
        return $this->message('修改成功');
    }

    public function fuwubiaozhun()
    {
        $services = Service::all();
        return view('service.fuwubiaozhun', ['services' => $services]);
    }

    public function fuwuyoushi()
    {
        $advantages = Advantage::all();
        return view('service.fuwuyoushi', ['advantages' => $advantages]);
    }

    public function fuwuxiangmu()
    {
        $services = Service::all();
        return view('service.fuwuxiangmu', ['services' => $services]);
    }
}
